/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package filer;

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 *
 * @author maggie
 */
public class Webloc extends UrlShortcut {

	private Document xmlDoc;

	public Webloc(String filePath) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true);
		DocumentBuilder db = dbf.newDocumentBuilder();
		this.xmlDoc = db.parse(new File(filePath));
		XPathFactory xpf = XPathFactory.newInstance();
		XPath xp = xpf.newXPath();
		XPathExpression xpe1 = xp.compile("/plist/dict/string");
		this.url = (String)xpe1.evaluate(this.xmlDoc, XPathConstants.STRING);
		// TODO HTML parse
		this.title = UrlShortcut.getNameWithoutExtension(new File(filePath).getName());
		File f = new File(filePath);
		this.lastModified = f.lastModified();

	}
}
